//
//  XYTitleView.swift
//  SinaWB_XY
//
//  Created by 小熊猫 on 15/10/10.
//  Copyright © 2015年 小熊猫. All rights reserved.
//

import UIKit

class XYTitleView: UIView,UITextFieldDelegate {
    @IBOutlet weak var cancelButton: UIButton!

    @IBOutlet weak var inputField: UITextField!
    @IBOutlet weak var inputRLine: NSLayoutConstraint!
    
    class func loadTitleView()->UIView{
        return NSBundle.mainBundle().loadNibNamed("TitleView", owner: nil, options: nil).last as! XYTitleView
    }
   
    override func awakeFromNib() {
        
        inputField.layer.borderColor=UIColor.redColor().CGColor
        inputField.layer.borderWidth=1
        inputField.layer.cornerRadius = 5
        //设置输入框左侧的图片
        let leftV = UIImageView(image: UIImage(named:"searchbar_textfield_search_icon"))
        //设置左侧View大小
        leftV.size=CGSizeMake(height, height)
        //设置图片显示方式
        leftV.contentMode = UIViewContentMode.Center
        //设置左侧View的显示方式
        inputField.leftView=leftV
        inputField.leftViewMode=UITextFieldViewMode.Always
        
        inputField.delegate=self
        
    }

    func textFieldDidBeginEditing(textField: UITextField) {
        
        printLog("开始输入LOG")
        
        self.inputRLine.constant = 45
        UIView.animateWithDuration(0.25) { () -> Void in
            self.layoutIfNeeded()
        }
    }
    
    func textFieldDidEndEditing(textField: UITextField) {
        printLog("结束输入")
    }
    //取消按钮的点击事件
    @IBAction func didCancelButton(sender: UIButton) {
        
        endEditing(true)
        self.inputRLine.constant = 0
        UIView.animateWithDuration(0.25) { () -> Void in
            self.layoutIfNeeded()
        }
        
    }

}
